import { Pipe, PipeTransform } from '@angular/core';

import { DictService } from '../../core/dict/dict.service';

@Pipe({
  name: 'bzDict'
})
export class DictPipe<U, D> implements PipeTransform {

  constructor(private dictService: DictService<U, D>) {

  }

  transform(dictKey: D, storageName?: string, params?: any): Promise<any[]> {
    if (!dictKey) {
      return Promise.resolve([]);
    }
    return this.dictService.getDict([dictKey], storageName, params).then((arr) => {
      return arr[0];
    });
  }

}
